* GSS data setup for: 
* Class, Policy Attitudes and U.S. Presidential Voting in the Post-Industrial Era: The Importance of Issue Salience
* Franko & Witko
* Political Research Quarterly
* Date: 05/25/22

* This code was created by Stephen L. Morgan and can be found at:
* https://osf.io/9nkrw/

clear all
set more off


********************************************************************************
*** Import csv crosswalk file and save as temporary merge file
********************************************************************************

tempfile egp_merge_file

import delimited using "occ10-to-egp-class-crosswalk.csv"
drop egp_label
save `egp_merge_file'

********************************************************************************
*** Load GSS cumulative file
********************************************************************************

use GSS_Class.dta, clear

********************************************************************************
*** Merge EGP codes by occ10
********************************************************************************

merge m:1 occ10 using `egp_merge_file'
tab _merge
list title if _merge==2
*drop if _merge==2
drop _merge

********************************************************************************
*** Label 10-class version of EGP (with combined class IVab)
********************************************************************************

tab egp10_10, miss
label define egproman10 1 "I" 2 "II" 3 "IIIa" 4 "IIIb" 7 "IVc" 8 "V" ///
  9 "VI" 10 "VIIa" 11 "VIIb" 12 "Military"
label values egp10_10 egproman10
tab egp10_10, miss
tab egp10_10 wrkstat, miss

********************************************************************************
*** Create 11-class version (with combined class IVab)
********************************************************************************

gen egp10_11 = egp10_10
replace egp10_11 = 5 if egp10_10 != 1 & egp10_10 != 2 & egp10_10 != 7 ///
        & egp10_10 != 12 & egp10_10 != . & wrkslf == 1 
label define egproman11 1 "I" 2 "II" 3 "IIIa" 4 "IIIb" 5 "IVab" 7 "IVc" ///
  8 "V" 9 "VI" 10 "VIIa" 11 "VIIb" 12 "Military"
label values egp10_11 egproman11
tab egp10_11 wrkslf, miss
tab egp10_11 wrkstat, miss
tab egp10_10 egp10_11, miss

********************************************************************************
*** Create 12-class version (with classes IVa and IVb) [GSS 2004 and later only]
********************************************************************************

***** Can't use the 12-class version with over time analysis. The "number of
***** employees" question is only asked in 2004 and later.

*** NOTE:  For this coding, we differentiate class IVa from IVb based on whether 
***        class IVab members have one or more employees. In some codings of 
***        the EGP class schema, a higher threshold is used, such as having 10 
***        or more employees.

*gen egp10_12 = egp10_10
*replace egp10_12 = 5 if egp10_10 != 1 & egp10_10 != 2 & egp10_10 != 7 ///
* & egp10_10 != 12 & egp10_10 != . & wrkslf == 1 & numemps > 0 & numemps < .
*replace egp10_12 = 6 if egp10_10 != 1 & egp10_10 != 2 & egp10_10 != 7 ///
* & egp10_10 != 12 & egp10_10 != . & wrkslf == 1 & numemps==0
*replace egp10_12 = . if year < 2004
*label define egproman12 1 "I" 2 "II" 3 "IIIa" 4 "IIIb" 5 "IVa" 6 "IVb" ///
*  7 "IVc" 8 "V" 9 "VI" 10 "VIIa" 11 "VIIb" 12 "Military"
*label values egp10_12 egproman12
*tab egp10_10 egp10_12, m
*tab egp10_12 wrkslf, m
*tab egp10_12 numemps, m
*tab egp10_12 wrkstat, m
*tab egp10_12 year, m

*codebook egp*, c
*bys egp10_10:  tab occ10 egp10_11

********************************************************************************
*** Save merged file
********************************************************************************

save GSS_Class_wEGP.dta, replace
